/**
 * Copyright (C), 2020, Y2 T205
 * FileName: SeckillController
 * Author: Lenovo
 * Date: 2020-05-31 13:53
 * Description:
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */


package com.atguigu.gulimall.seckill.controller;


import com.atguigu.common.utils.R;
import com.atguigu.gulimall.seckill.service.SeckillService;
import com.atguigu.gulimall.seckill.to.SeckillSkuRedisTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.security.Key;
import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author Lenovo
 * @create 2020-05-31
 * @since 1.0.0
 */
@Controller
public class SeckillController {

    @Autowired
    SeckillService seckillService;
   @ResponseBody
    @GetMapping("/currentSeckillSkus")
    public R getCurrentSeckillSkus(){

       List<SeckillSkuRedisTo> vos= seckillService.getCurrentSeckillSkus();

        return R.ok().setData(vos);
    }

@ResponseBody
    @GetMapping("/sku/seckill/{skuId}")
    public R getSkuSeckillInfo(@PathVariable("skuId") Long skuId){
       SeckillSkuRedisTo to= seckillService.getSkuSeckillInfo(skuId);
       return R.ok().setData(to);
    }

    @GetMapping("/kill")
    public String secKill(@RequestParam("killId") String killId,
                     @RequestParam("key")String key,
                     @RequestParam("num")Integer num,
                          Model model
    ){
//        1.判断是否登录


       String orderSn=seckillService.kill(killId,key,num);

       model.addAttribute("orderSn",orderSn);
       return "success";
    }


}
